﻿#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys
import unittest

if __name__ == '__main__':
    current_dir = os.path.abspath(".")
    totalTestsRun = 0
    totalErrors = 0
    totalFailures = 0

    for root, dirs, files in os.walk("."):
        for file in files:
            if file.startswith("test_") and file.endswith(".py"):
                testmodule_dir = os.path.abspath(root)

                os.chdir(testmodule_dir)
                sys.path[0] = testmodule_dir               

                testmodule = file.split(".", 1)[0]
                testRunner = unittest.TextTestRunner(verbosity=1)
                testLoader = unittest.TestLoader()
                suite = testLoader.loadTestsFromName(testmodule)                
                print "\n>> Test module: %s (%s)\n" % (testmodule, testmodule_dir) 
                result = testRunner.run(suite)
                totalTestsRun += result.testsRun
                totalErrors += len(result.errors)
                totalFailures += len(result.failures)

                os.chdir(current_dir)

    os.chdir(current_dir)
    print "\n>> TOTAL RESULT: Ran %s, Errors: %s, Failures: %s" % (totalTestsRun, totalErrors, totalFailures)